<?php
session_start();
$name=$_SESSION['user-name'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>超市管理系统</title>
    <link rel="stylesheet" href='style/subper.css'/>
    <style>
    .main_right{
      background: url(images/stars-opacity.0979c1.svg);
      background-color:#d9d9d9;
      position: relative;
      overflow:hidden;
    }

        </style>
</head>

<script>
    function tjsp(){
        document.getElementById('b1').style.display='block';
        document.getElementById('b2').style.display='none';
        document.getElementById('b3').style.display='none';
        document.getElementById('b4').style.display='none';
        document.getElementById('b5').style.display='none';
    }
    function glsp(){
        document.getElementById('b1').style.display='none';
        document.getElementById('b2').style.display='block';
        document.getElementById('b3').style.display='none';
        document.getElementById('b4').style.display='none';
        document.getElementById('b5').style.display='none';
    }
    function yybb(){
        document.getElementById('b1').style.display='none';
        document.getElementById('b2').style.display='none';
        document.getElementById('b3').style.display='block';
        document.getElementById('b4').style.display='none';
        document.getElementById('b5').style.display='none';
    }
    function ckkc(){
        document.getElementById('b1').style.display='none';
        document.getElementById('b2').style.display='none';
        document.getElementById('b3').style.display='none';
        document.getElementById('b4').style.display='block';
        document.getElementById('b5').style.display='none';
    }
    function grzx(){
        document.getElementById('b1').style.display='none';
        document.getElementById('b2').style.display='none';
        document.getElementById('b3').style.display='none';
        document.getElementById('b4').style.display='none';
        document.getElementById('b5').style.display='block';
    }
    function tcxt(){
    var tc=window.confirm("您确定要退出系统吗？");
 if(tc==true){
     window.location.href="index.php";
 }
 else{
     alert('您取消了退出系统');
 }
}
function tcdl(){
    var tc=window.confirm("您确定要退出登录吗？");
 if(tc==true){
     window.location.href="login.html";
 }
 else{
     alert('您取消了退出登录');
 }
}
function sc(){
    alert("删除成功");
}
function check(){
  var a1=document.getElementById('dlmc').innerHTML;
  var a2=document.getElementById('rkzmc').value;
  if(a1!=a2){
    alert('入库者名称必须是登录名称！');
  return false;
  } 

}


</script>
<body>
    <div class=main_top>
        <h3>超市管理系统</h3>
        <?php echo "<p id=dlmc hidden>$name</p>" ?>
        <?php echo "<p>欢迎您 $name 管理员&nbsp;&nbsp;&nbsp;<button onclick=tcdl()>退出登录</button></p>"; ?>
    </div>
    <div class=main>
    <div class=main_left>
       <a href='#a'><button id=a1 onclick="tjsp()" >添加商品</button></a>
       <a href='#a'><button  id=a2 onclick="glsp()">管理商品</button></a>
    <div class=left_botton>
    <a href='#a'><button id=a3 onclick="yybb()"><img src=images/营业报表.png width="60px" height="60px"><br/>营业报表</button></a>
    <a href='#a'><button id=a4 onclick="ckkc()"><img src=images/查看库存.png width="60px" height="60px"><br/>查看库存</button></a>
    <a href='#a'><button id=a5 onclick="grzx()"><img src=images/个人中心1.png width="60px" height="60px"><br/>个人中心</button></a>
    <a href='#a'><button id=a6 onclick="tcxt()"><img src=images/退出系统.png width="60px" height="60px" id=tx><br/>退出系统</button></a>
    </div> 
    </div>
    <div class=main_right id=a>
        <!--------动画部分-------->
        <li class=li_top></li>
        <li class=li_right></li>
        <li class=li_bottom></li>
        <li class=li_left></li>
    <!-----------添加商品-------->
      <div id=b1><h4>添加商品</h4><br/>
          <form action="addproduct.php" method="POST" enctype="multipart/form-data" onsubmit="return check()">
              商品名称：<input type=text name=productname size='20' class=spmcsrk required placeholder="请输入商品名称" /><br/>
              商品类型：<select name=producttype class=splx>
                   <option>零食类</option>
                   <option>饮料类</option>
                   <option>文具类</option>
                   <option>日用品类</option>
                   <option>菜类</option>
                   <option>酒类</option>
                   <option>奶类</option>
                    </select>
              &nbsp;&nbsp;商品价格：<input type=text name=productprice size=20 class=splx  required placeholder="可带单位"/><br/>
              商品数量：<input type=text name=productcount  size=20 class=splx  required placeholder="输入数字即可" />
              &nbsp;&nbsp;入库日期：<input type=date name=date size=20 class=splx required /><br/>
             入库者名称：<input type=text name=inputname  size=20 class=splx1 id=rkzmc required placeholder="入库者名称必须是登录的用户名" />
             &nbsp;&nbsp; 商品图片：<input type="file" name=picture required /><br/>
              <input type="submit" class=tjann value=添加>
          </form>
        </div>

        
        <!---------管理商品----->
     <?php
     
     ?>
        <div id=b2><h4>管理商品</h4><br/>
        <form action="#" method="POST">
        商品名称：<input type=text name=spmcselect size=20 class=ssk required placeholder="请输入查询的商品名称或者类型" />
        <input type="submit" value="查询" class=cxann /> 
        </form>
        <div class=splb>
        <?php
          $serverLink=@mysql_connect("localhost","root","root") or die("连接服务器失败！程序中断");
          mysql_query("'set names 'utf-8'");
          $dbLink=@mysql_select_db("supermarket") or die("打开supermarket数据库失败！程序中断");
         
          /*   模糊匹配   */
          if(isset($_POST['spmcselect'])){
            $spname=$_POST['spmcselect'];
            $select="select * from product where inputname='$name' and productname like '%$spname%' or inputname='$name' and producttype like '%$spname%'";
              $sqlsp=mysql_query($select);
              $sum=mysql_affected_rows();//计算总数据
          }else{
               /*没有查询显示*/
         $select="select * from product where inputname='$name'";
          $sqlsp=mysql_query($select);
          $sum=mysql_affected_rows();//计算总数据
          }
        $pagesize=3;//页面条数
        $pagecount=ceil($sum/$pagesize);//总页数 
        $pageno=isset($_GET['pageno'])?$_GET['pageno']:1;//获得传递的当前页码
        if($pageno<1){
           $pageno=1;
        }
        if($pageno>$pagecount){
           $pageno=$pagecount;
            }
            $startno=($pageno-1)*$pagesize;//计算当前页面的起始位置

        /*   模糊匹配   */
     if(isset($_POST['spmcselect'])){
        $spname=$_POST['spmcselect'];

        $select="select * from product where inputname='$name' and productname like '%$spname%' or inputname='$name' and producttype like '%$spname%' order by inputdate desc limit $startno,$pagesize";
          $sqlsp=mysql_query($select);
          $fhz=mysql_affected_rows();
          
          if($fhz<='0'){
              echo "您的仓库中没有此商品";
          }

        }else{
     /*没有查询则默认显示全部商品信息*/
          $select="select * from product where inputname='$name' order by inputdate desc limit $startno,$pagesize ";
          $sqlsp=mysql_query($select);
        }
        if($sum<='0'){
            echo "您的商品空空如也！";
        }else{

        
        echo "<table border=1 rules='all'>
        <tr>
        <th style=background-color:#0fd2de>商品名称
        <th style=background-color:#0fd2de>商品类型
        <th style=background-color:#0fd2de>价格
        <th style=background-color:#0fd2de>数量
        <th style=background-color:#0fd2de>图片
        <th style=background-color:#0fd2de>操作
        </tr>";
        
        while($db=mysql_fetch_array($sqlsp)){
            echo "<tr><td>";
             echo $db['productname']." ";
             echo "<td>";
             echo $db['producttype']." ";
             echo "<td>";
             echo $db['productprice']."<br/>";
             echo "<td>";
             echo $db['productcount']."<br/>";
             echo "<td>";
            $a=$db['picturesrc'];
             echo "<img src='$a' width=100px height=100px />";
             echo "<td>";
             echo '<a target=_blank href="look.php?iid='.$db['Id'].'"><button  class=ckan>查看</button></a>'." ";
             echo '<a target=_blank href="update.php?iid='.$db['Id'].'"><button  class=xgan>修改</button></a>'." ";
             echo '<a target=_blank href="subper.php?iid='.$db['Id'].'"><button onclick=sc()  class=scan>删除</button></a>'." ";
             echo "</tr>"; 
        
         }
       echo" </table>";
       echo "总页数：".$pagecount."  ";
       echo "当前页：".$pageno." ";
       echo "总商品数为：".$sum."  ";
       echo "</div>";
   
       

       echo "<div class=fyann>";
      echo '<a href="subper.php?pageno=1"><button>首页</button></a>&nbsp;';
      echo '<a href="subper.php?pageno='.($pageno-1).'"><button id=btn01><<</button></a>';//上一页按钮
      if($pagecount>3){
          $pagecount2=$pagecount;
          $pagecount=3;
          
      }
       for($i=1;$i<=$pagecount;$i++){
           echo '<a href="subper.php?pageno='.$i.'"> <button id=btn01>'.$i.' </button></a>&nbsp;';
       }
       //更多页码
       if($pagecount2>3){
        echo '<div class=a style=width:50px>';
        echo '<button id=btn01 >...</button>&nbsp;';
        for($i=4;$i<=$pagecount2;$i++){
            echo '<div class=aa><a href="subper.php?pageno='.$i.'"> <button id=btn01 class=btn01>'.$i.' </button></a></div>&nbsp;';
        }
        echo'</div>';
    }

       echo '<a href="subper.php?pageno='.($pageno+1).'"><button id=btn01>>></button></a>&nbsp;';  //下一页按钮
       if($pagecount2 <= 3){
        echo '<a href="subper.php?pageno='.$pagecount.'"><button>末页</button></a>';
       }else{
       echo '<a href="subper.php?pageno='.$pagecount2.'"><button>末页</button></a>';
       }
       echo '</div>';
    echo '</div>';


       /*  删除商品*/
       if(isset($_GET['iid'])){
           $dat=$_GET['iid'];
           $deletesql="delete from product where Id='$dat'";
           mysql_query($deletesql);
       }
    }
        ?>
        


<!-----------营业报表-------->
      <div id=b3><h4>营业报表</h4>
        <form action="saleslist.php" method="POST">
        
     选择查询日期：<input type=date name=select size=20 class=cxrq required>
     <select name=selecttype >
                   <option>年销售</option>
                   <option>月销售</option>
                   <option>日销售</option>
                    </select>
<input type="submit" value="查询" class=selectann>
    </div>

      <!-------------查看库存-------->
      <div id=b4><h4>查看库存</h4>
     <div class=kc>   
        <?php
       echo '  
    <a href="repertory.php?name='.$name.'&type=零食类" target=_blank ><input type=button class="lskc" value=零食库存></a>
    <a href="repertory.php?name='.$name.'&type=饮料类" target=_blank ><input type=button class="ylkc" value=饮料库存></a>
    <a href="repertory.php?name='.$name.'&type=文具类" target=_blank ><input type=button class="wjkc" value=文具库存></a><br/>
    <a href="repertory.php?name='.$name.'&type=日用品类" target=_blank ><input type=button class="rypkc" value=日用品库存></a><br/>
    <a href="repertory.php?name='.$name.'&type=菜类" target=_blank ><input type=button class="clkc" value=菜类库存></a>
    <a href="repertory.php?name='.$name.'&type=酒类" target=_blank ><input type=button class="jlkc" value=酒类库存></a>
    <a href="repertory.php?name='.$name.'&type=奶类" target=_blank ><input type=button class="nlkc" value=奶类库存></a>
    ';
    ?>
    </div>
    </div>


      <!-----------个人中心---------->
   
      <div id=b5><h4>个人中心</h4><br/> 
      <?php
    $selectadm="select * from admsign  where admname='$name'";
    $sqladm=mysql_query($selectadm);
    $outadm=mysql_fetch_assoc($sqladm);
     echo "<p>用户名："." ".$outadm['admname']."</p><br/>";
     echo "<p>邮箱地址："." ".$outadm['email']."</p><br/>";
     echo "<p>手机号码："." ".$outadm['phtonumber']."</p><br/>";
    echo  '<a href="modification.php?name='.$name.'&type=修改信息"  target=_blank ><input type=button class="xgxx" value=修改信息></a>';
    echo  '<a href="modification.php?name='.$name.'&type=修改密码"  target=_blank ><input type=button class="xgmm" value=修改密码></a>';
   echo'<input type=button class=tcdl onclick="tcdl()" value="退出登录" />';
?>
<?php mysql_close($serverLink); ?>
    </div>
    </div>
    </div>


</body>
</html>